package com.example.firstjavamqtt.controller.log_api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.firstjavamqtt.common.result.Result;
import com.example.firstjavamqtt.common.result.ResultCodeEnum;
import com.example.firstjavamqtt.model.device.TemperatureHumidityMonitor;
import com.example.firstjavamqtt.model.dto.log.TemperatureHumidityLogDto;
import com.example.firstjavamqtt.model.log.DeviceLog;
import com.example.firstjavamqtt.model.log.TemperatureHumidityMonitorLog;
import com.example.firstjavamqtt.service.log.TemperatureHumidityLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;

@RestController
@RequestMapping("/log/temperatureHumidity")
@Api(tags = "温度湿度日志接口")
public class TemperatureHumidityLogController {

    @Autowired
    TemperatureHumidityLogService temperatureHumidityLogService;

    @ApiOperation(value = "根据dto分页获取温度日志列表")
    @GetMapping("/getAllByDto/{pageNum}/{limit}")
    public Result getAllDeviceLogByDto(@PathVariable int pageNum,
                                  @PathVariable int limit,
                                  TemperatureHumidityLogDto dto) {
        Page<TemperatureHumidityMonitorLog> pageModel = temperatureHumidityLogService.getLogByDto(dto,pageNum, limit);
        return Result.ok(pageModel);
    }

    @ApiOperation(value = "分页获取温度日志列表")
    @GetMapping("/getAll/{pageNum}/{limit}")
    public Result getAllDeviceLog(@PathVariable int pageNum,
                                  @PathVariable int limit
                                 ) {
        Page<TemperatureHumidityMonitorLog> pageModel = temperatureHumidityLogService.getLog(pageNum, limit);
        return Result.ok(pageModel);
    }

    @ApiOperation(value = "根据设备ID温度日志列表")
    @GetMapping("/getByDeviceId/{pageNum}/{limit}/{deviceId}")
    public Result getAllDeviceLog(@PathVariable int pageNum,
                                  @PathVariable int limit,
                                  @PathVariable String deviceId,
                                  HttpServletRequest request) {
        Page<TemperatureHumidityMonitorLog> pageModel = temperatureHumidityLogService.getByDeviceId(pageNum, limit,deviceId,request);
        return Result.ok(pageModel);
    }

    @ApiOperation("根据id删除温度湿度日志")
    @GetMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable int id) {
        temperatureHumidityLogService.deleteTemperatureHumidityLogById(id);
        return Result.ok();
    }

    @ApiOperation("根据deviceId删除温度湿度日志")
    @GetMapping("/deleteByDeviceId/{deviceId}")
    public Result deleteByDeviceId(@PathVariable String deviceId) {
        temperatureHumidityLogService.deleteTemperatureHumidityLogByDeviceId(deviceId);
        return Result.ok();
    }

    @ApiOperation("根据批量ID删除温度湿度日志")
    @GetMapping("/deleteByBatchId/{batchId}")
    public Result deleteByBatchId(@PathVariable ArrayList<Integer> batchId) {
        temperatureHumidityLogService.deleteLedLogByBatchId(batchId);
        return Result.ok();
    }
}
